//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package wudashan;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.HeadlessException;
import java.awt.Insets;
import java.awt.Toolkit;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import ui.MyOutMessagePane;
import ui.MyTextPane;
import wudashan.ui.CommandButtonGroup;
import wudashan.ui.CommandLabel;
import wudashan.ui.CommandNoRadioButtion;
import wudashan.ui.CommandYesRadioButtion;
import wudashan.ui.DataButton;
import wudashan.ui.DataTextArea;
import wudashan.ui.EPLabel;
import wudashan.ui.EPTextField;
import wudashan.ui.IPLabel;
import wudashan.ui.IPTextField;
import wudashan.ui.LogLabel;
import wudashan.ui.LogScrollPane;
import wudashan.ui.LogTextArea;
import wudashan.ui.PSKLabel;
import wudashan.ui.PSKTextField;
import wudashan.ui.RegisterButton;

public class EDRXSimulator extends JFrame {
    private SimulatorResource resource = new SimulatorResource("d", this);
    private SimulatorServer server;
    private boolean hasRegister;
    private boolean isUseSecure;
    private GridBagLayout layout;
    private GridBagConstraints constraints;
    private JLabel ipLabel;
    private JTextField ipTextField;
    private JLabel epLabel;
    private JTextField epTextField;
    private JLabel pskLabel;
    private JTextField pskTextField;
    private JButton registerButton;
    private JSeparator separator1;
    private JLabel logLabel;
    private LogTextArea logTextArea;
    private JScrollPane logScrollPane;
    private JSeparator separator2;
    private JTextArea dataTextArea;
    private JTabbedPane tabbedPane;
    private JTextPane hexMsgArea;
    private JTextPane jsonMsgArea;
    private JButton dataButton;
    private JSeparator separator3;
    private JLabel commandLabel;
    private JRadioButton commandYesRadioButtion;
    private JRadioButton commandNoRadioButtion;
    private ButtonGroup commandButtonGroup;

    public EDRXSimulator() throws HeadlessException {
        super("NB-IoT终端模拟器 ");
        this.server = new SimulatorServer(this.resource, this);
        this.hasRegister = false;
        this.isUseSecure = false;
        this.layout = new GridBagLayout();
        this.constraints = new GridBagConstraints();
        this.ipLabel = new IPLabel();
        this.ipTextField = new IPTextField();
        this.epLabel = new EPLabel();
        this.epTextField = new EPTextField();
        this.pskLabel = new PSKLabel();
        this.pskTextField = new PSKTextField();
        this.registerButton = new RegisterButton(this);
        this.separator1 = new JSeparator();
        this.logLabel = new LogLabel();
        this.logTextArea = new LogTextArea();
        this.separator2 = new JSeparator();
        this.dataTextArea = new DataTextArea();
        this.tabbedPane = new JTabbedPane();
        this.hexMsgArea = new MyTextPane();
        this.jsonMsgArea = new MyTextPane();
        this.dataButton = new DataButton(this);
        this.separator3 = new JSeparator();
        this.commandLabel = new CommandLabel();
        this.commandYesRadioButtion = new CommandYesRadioButtion(this);
        this.commandNoRadioButtion = new CommandNoRadioButtion(this);
        this.commandButtonGroup = new CommandButtonGroup(this.commandYesRadioButtion, this.commandNoRadioButtion);
        Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
        this.setSize(650, 750);
        int width = (int)dimension.getWidth();
        this.setLocation(width - this.getWidth(), 0);
        this.setResizable(false);
        this.setDefaultCloseOperation(3);
        this.setLayout(this.layout);
        this.setConstraints(1, 0, 0, 1, 1, new Insets(5, 5, 5, 5));
        this.add(this.ipLabel, this.constraints);
        this.setConstraints(1, 0, 1, 1, 1, (Insets)null);
        this.add(this.ipTextField, this.constraints);
        this.setConstraints(1, 0, 2, 1, 1, (Insets)null);
        this.add(this.epLabel, this.constraints);
        this.setConstraints(1, 0, 3, 1, 1, (Insets)null);
        this.add(this.epTextField, this.constraints);
        this.setConstraints(1, 0, 4, 1, 1, (Insets)null);
        this.add(this.pskLabel, this.constraints);
        this.setConstraints(1, 0, 5, 1, 1, (Insets)null);
        this.add(this.pskTextField, this.constraints);
        this.setConstraints(1, 0, 6, 1, 1, (Insets)null);
        this.add(this.registerButton, this.constraints);
        this.setConstraints(1, 1, 0, 7, 1, (Insets)null);
        this.add(this.separator1, this.constraints);
        this.setConstraints(1, 2, 0, 7, 1, (Insets)null);
        this.add(this.logLabel, this.constraints);
        this.setConstraints(1, 3, 0, 7, 5, (Insets)null);
        this.add(this.logTextArea, this.constraints);
        this.setConstraints(1, 3, 0, 7, 5, (Insets)null);
        this.logScrollPane = new LogScrollPane(this.logTextArea);
        this.add(this.logScrollPane, this.constraints);
        this.setConstraints(1, 8, 0, 7, 1, (Insets)null);
        this.add(this.separator2, this.constraints);
        this.setConstraints(1, 9, 0, 7, 1, (Insets)null);
        this.add(this.tabbedPane, this.constraints);
        JPanel hexMsgPanel = new MyOutMessagePane("Hex消息:", this.hexMsgArea, 600, 200);
        this.tabbedPane.add("十六进制码流", hexMsgPanel);
        JPanel jsonMsgPanel = new MyOutMessagePane("JSON消息:", this.jsonMsgArea, 600, 200);
        this.tabbedPane.add("JSON", jsonMsgPanel);
        this.setConstraints(1, 15, 0, 7, 1, (Insets)null);
        this.add(this.dataButton, this.constraints);
        this.setConstraints(1, 16, 0, 7, 1, (Insets)null);
        this.add(this.separator3, this.constraints);
        this.setConstraints(1, 17, 0, 7, 1, (Insets)null);
        this.add(this.commandLabel, this.constraints);
        this.setConstraints(1, 17, 4, 2, 1, (Insets)null);
        this.add(this.commandYesRadioButtion, this.constraints);
        this.setConstraints(1, 17, 6, 2, 1, (Insets)null);
        this.add(this.commandNoRadioButtion, this.constraints);
        ImageIcon icon = new ImageIcon("images/UE.png");
        this.setIconImage(icon.getImage());
        this.setVisible(true);
        int response = JOptionPane.showConfirmDialog(this, "是否开启DTLS加密传输？", "提示", 0);
        if (response == 0) {
            this.logTextArea.printLog("已选择DTLS加密传输通道!", new Object[0]);
            this.isUseSecure = true;
        } else {
            this.logTextArea.printLog("未选择DTLS加密传输通道，无需填写PSK！", new Object[0]);
            this.isUseSecure = false;
            this.pskLabel.setVisible(false);
            this.pskTextField.setVisible(false);
        }

    }

    private void setConstraints(int fill, int gridy, int gridx, int gridwidth, int gridheight, Insets insets) {
        this.constraints.fill = fill;
        this.constraints.gridy = gridy;
        this.constraints.gridx = gridx;
        this.constraints.gridwidth = gridwidth;
        this.constraints.gridheight = gridheight;
        if (insets != null) {
            this.constraints.insets = insets;
        }

    }

    public JTabbedPane getTabbedPane() {
        return this.tabbedPane;
    }

    public JTextPane getHexMsgArea() {
        return this.hexMsgArea;
    }

    public JTextPane getJsonMsgArea() {
        return this.jsonMsgArea;
    }

    public JTextField getIpTextField() {
        return this.ipTextField;
    }

    public JTextField getEpTextField() {
        return this.epTextField;
    }

    public SimulatorResource getResource() {
        return this.resource;
    }

    public SimulatorServer getServer() {
        return this.server;
    }

    public JTextArea getDataTextArea() {
        return this.dataTextArea;
    }

    public boolean isHasRegister() {
        return this.hasRegister;
    }

    public void setHasRegister(boolean hasRegister) {
        this.hasRegister = hasRegister;
    }

    public boolean isUseSecure() {
        return this.isUseSecure;
    }

    public LogTextArea getLogTextArea() {
        return this.logTextArea;
    }

    public JTextField getPskTextField() {
        return this.pskTextField;
    }

    public static void main(String[] args) {
        new EDRXSimulator();
    }
}
